import { Cascader, Button, Select } from 'antd'
import { useContext } from 'react'
import { useRecoilValue } from 'recoil'
import { reportReviewContext } from '../../_context'
import IconSvg from '@/components/IconSvg'
import styles from './index.module.less'
import { theQuarterData } from '@/store/user'
import { dictValues } from '@/store/dicts'
import { isNullArray } from '@/utils'

export default () => {
  const quarterData = useRecoilValue(theQuarterData)
  const dictValuesList = useRecoilValue(dictValues)

  const {
    task,
    handleTaskChange,
    handleStatusChange,
    handleReport,
    handleWordChange,

    wordList,
    hospitals,
    selectWord,
    status,
    tableList,
    isShowBtn,
  } = useContext(reportReviewContext)

  return (
    <>
      <div className={styles.contenttop}>
        <div>医院加入时间：{hospitals?.hospitalApplyTime}</div>
        <div>当前需要填报的季度：{hospitals?.quarterNow}</div>
      </div>
      <div className={styles.search}>
        <div className={styles.rightflex}>
          <Cascader
            value={task}
            className={styles.width200}
            onChange={(e) => handleTaskChange(e)}
            options={quarterData}
            placeholder={'请选择任务'}
            displayRender={(value) => value.join('')}
            allowClear={false}
          />
          <Select
            value={selectWord}
            className={styles.width200}
            onChange={(e) => handleWordChange(e)}
            key={'value'}
            options={
              isNullArray(wordList) ? wordList.map((item) => ({ label: item.wordName, value: item.wordId })) : []
            }
            placeholder={'请选择病区'}
          />
          <Select
            className={styles.width200}
            value={status}
            onChange={(e) => handleStatusChange(e)}
            options={[{ label: '全部', value: '' }, ...dictValuesList.report_status]}
            placeholder='请选择状态'
          />
        </div>
        {hospitals?.isApply !== 'Y' && (
          <Button
            onClick={handleReport}
            className={styles.exportbtn}
            type='primary'
            ghost
            disabled={!isShowBtn}
            icon={<IconSvg name='reporting-platform' />}
          >
            上报省平台
          </Button>
        )}

        {hospitals?.isApply === 'Y' && <div>已上报省平台：{hospitals?.reportPlatformTime}</div>}
      </div>
    </>
  )
}
